﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ZLCMS.Business;
using NHibernate;
using ZLCMS.Data.Model;
using NHibernate.Criterion;
using ZLCMS.Business.DwzFrame;
using ZLCMS.Business.Util;
using Newtonsoft.Json;

namespace ZLCMS.Web.SystemManage.Basics.Advert
{
    public partial class AdvertPositionList : System.Web.UI.Page
    {
        protected FrameHelper _framePage;

        protected void Page_Load(object sender, EventArgs e)
        {
            //初始化DWZ分页控件
            _framePage = new FrameHelper(this) { RecordCount = GetListCount() };

            //填充网格数据
            BindList(_framePage.PageIndex, _framePage.PageSize);

        }
        #region 填充网格数据 + protected void BindList(int pageIndex, int pageSize)
        /// <summary>
        /// 填充网格数据
        /// </summary>
        /// <param name="pageIndex">分页索引</param>
        /// <param name="pageSize">分页大小</param>
        protected void BindList(int pageIndex, int pageSize)
        {
            using (ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
            {
                ICriteria criteria = session.CreateCriteria<ShopAdvertPositonInfo>();

                criteria.SetFirstResult((pageIndex - 1) * pageSize).SetMaxResults(pageSize);

                grid.DataSource = criteria.List();
                grid.DataBind();
            }
        }
        #endregion

        #region 查询数据总数 + protected int GetListCount()
        /// <summary>
        /// 查询数据总数
        /// </summary>
        /// <returns></returns>
        protected int GetListCount()
        {
            using (ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
            {
                ICriteria criteria = session.CreateCriteria<ShopAdvertPositonInfo>();
  
                object obj = criteria.SetProjection(Projections.RowCount()).UniqueResult();
                return int.Parse(obj.ToString());
            }
        }
        #endregion

    }
}
